Welcome to Bryton in three hours.
Let's talk about functions to define the function, you use the keyboard if D, E, F, and then you
define the name of that function, I usually define the name of my functions, starting with the word
fun on the line.
And in this example, I call it test on the line zero one, then open and close prentice's.
Because if you remember, functions always go with parentheses and within the pantazis you define the
variables that that function going to get as its inputs.
In this example, my fondest one has only one input and that is X.
Again, we have a column and we start the next line with an indentation or in fact whatever comes under
this function should have one indentation.
This expression that you see here is the conditional statement that we have already practiced here.
So I just brought it here and I made sure that I have one indentation because of the diff.
And for each of if Elif and else, I have another indentation to make sure the corresponding expression
goes under the right key.
If you to sell this function is being stored into your memory, then you can call this function using
different input variables.
For example, in this cell, I'm going to call that function using the value of forty five has the input
of that function.
Let's run the cell.
Forty five is not divided well by two, but is divided by three and five commands.
Uncommented is run it again.
Forty two is divided by two commands and commands and run the again.
We have no comment regarding forty one.
Let's see more examples of functions.
But here we can actually have both for loops and a conditional statement.
In this example I define a function and I name it fantas to open and close Pantazis.
And this function has three inputs separated from each other using comma, one comma, another comma
and three input.
The first input is start on the line that the second input is stop on the line, Val, and the last
input is step on the line.
That and I assign some values into those inputs.
For example, start val equals to zero start that equals to ten and step back equals to one.
And what it does basically if you call this function later and you just define, let's say, the start,
Val, to be, let's say five, but you don't define the other inputs, then the function going to get
this value of ten and one for ostovar, stable and stable respectively as the default values and then
run this one, assuming that we are using the default values for these two inputs.
So these values here are basically the default values on this.
When you call the function, you particularly define a different value in this example because of the
function.
I have an indentation.
Then I start with the follow up with the counter.
I'm not in range of start that stubborn and still, Val, that we are inputting to that function.
Another indentation, because I want to define some conditional statement here.
And in this statement we're going to check if I not is divided by four.
And in that case we're going to print I not is divided by four.
But if that's not the case elif we check, if I'm not is divided well by two then we print.
I not is not divided well by four but is divided well by two.
And if none of those conditions go through, we have the LS condition and we print.
We have no comment for inat.
As you see I have one indentation for, for another indentation for things that come under four which
are basically if everyone else and an extra indentation for things that coming under if Arif and else.
If I run this all the function is being saved into my memory.
Let's practice that function.
For example, I say fun test to open and close pantazis start val equals to minus five star equals twenty
and a stable equals to five.
This so and for each of these values that I not is being assigned to, we have the corresponding message
that we define here.
Let me remove this symbol here and not define it.
In that case, my staff are going to be the default value that we define here, which is one this round
to sell.
Again, as you see, we have our following here goes from minus five to 20.
What is the value of one?
That's why we have too many messages here, because I not is getting too many integer values.
And for each we have the.
Corresponding message, we can also define functions that return for us some outputs here, I'm going
to define fun test three, which gets two inputs X and Y.
First, I'm going to check if X is divided by Y.
And in that case, my first output output one is equal to X to the power of Y and my second output is
X divided by Y.
If that condition is not true, then we have else.
So my first and second outputs both going to be in a slash a like not available or not applicable,
but in order to return these outputs as the outputs of my fantastic three, we are using the return
key function.
And as you see, we have only one indentation here similar to else.
And if because these are the first level expressions that are going with respect to my function, if
I have one more indentation here like that, then the function returns output one on two.
Only if else is true, because the indentation is such that it comes under my key.
So you have to pay attention carefully to these indentations.
Let's return to one indentation and whatever you put in front of your return key should be in the order
that you want those outputs to come out of your function.
For example, here I want to first get my first output and then my second output and I have it come
on here to separate them.
This, Randi, so and my Fonthill three is now in my memory.
Let's call that function here just to practice.
So I'm going to say my X is 25 and my Y is five.
And to get the outputs in the same order that I put them in the function, I call them like output one
and output to these names do not need to be the same as the names that have been defined here.
We can define them, for example, Z and T, whatever you want.
It doesn't matter, but the order is important.
Just make sure whatever you put here are getting your output one and whatever you put here are getting
your second output.
And here I have a brain function to just print for us.
This output one and two for the case of X equals two twenty five and Y equals two five.
Let's run the cell.
And as you see, since twenty five is divided by five, this condition went through and then your first
output is twenty five to the power of five, which is this value and the second output is twenty five
divided by five which is five.
What if I have twenty four here this round.
So as you see in my output is going to be not applicable like this and because the second condition
went through.
In this lecture, you learn about how to define followups in Python, how to create conditional statements
using, if anything else, and how to create functions in Python, in the next lecture, we will learn
about Nampara and pandas for data processing.
Thank you for your attention.
See you all in the next lecture.